<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算变量</title>
    <script src="https://unpkg.com/vue@next"></script>
  </head>
  <body>
    <div id="Application">
      
    </div>
  </body>

  <script>
    const App = Vue.createApp({
        setup(){
            /***
            let a =1
            let b =2
            let sum = a+b
            ***/
            let a = Vue.ref(1)
            let b = Vue.ref(2)
            /***
            let sum = Vue.computed(()=>{
                return a.value + b.value
            })
            ***/

            /*** 也支持getter/setter方式 **/
            let sum = Vue.computed({
              set(value){
                a.value = value;
                b.value = value;
              },
              get(){
                return a.value + b.value
              }
            }) 

            function click(){
                a.value +=1
                b.value +=2
                console.log(a)
                console.log(b)
            }
            return {
                sum,
                click
            }
        },
        template:`
            <h1>测试数据：{{sum}}</h1>
            <button @click="click">点击</button>
        `
    })
    App.mount("#Application")
  </script>

</html>